using MediatR;
using SumerCoreDevOps.Application.Workflows.Queries;
using SumerCoreDevOps.Infrastructure.Workflow;

namespace SumerCoreDevOps.Application.Workflows.Handlers;

/// <summary>
/// 验证工作流查询处理器
/// </summary>
public class ValidateWorkflowQueryHandler : IRequestHandler<ValidateWorkflowQuery, WorkflowValidationResult>
{
    private readonly WorkflowDefinitionManager _definitionManager;

    public ValidateWorkflowQueryHandler(WorkflowDefinitionManager definitionManager)
    {
        _definitionManager = definitionManager;
    }

    public async Task<WorkflowValidationResult> Handle(ValidateWorkflowQuery request, CancellationToken cancellationToken)
    {
        var (isValid, errors) = await _definitionManager.ValidateWorkflowAsync(request.Id);
        return new WorkflowValidationResult(isValid, errors);
    }
}
